<%@page import="java.util.*"%>
<%@page import="java.text.*"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>


<%
    String path = request.getContextPath(); 
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+path+ "/"; 
	
       Object coupon = request.getAttribute("coupon");
       
       
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<base href="<%=basePath%>">
<style type="text/css">
a{ text-decoration:none;}
a:hover{ text-decoration:none;}
.tcdPageCode{padding: 15px 20px;text-align: left;color: #ccc;text-align:center;}
.tcdPageCode a{display: inline-block;color: #428bca;display: inline-block;height: 25px;	line-height: 25px;	padding: 0 10px;border: 1px solid #ddd;	margin: 0 2px;border-radius: 4px;vertical-align: middle;}
.tcdPageCode a:hover{text-decoration: none;border: 1px solid #428bca;}
.tcdPageCode span.current{display: inline-block;height: 25px;line-height: 25px;padding: 0 10px;margin: 0 2px;color: #fff;background-color: #428bca;	border: 1px solid #428bca;border-radius: 4px;vertical-align: middle;}
.tcdPageCode span.disabled{	display: inline-block;height: 25px;line-height: 25px;padding: 0 10px;margin: 0 2px;	color: #bfbfbf;background: #f2f2f2;border: 1px solid #bfbfbf;border-radius: 4px;vertical-align: middle;}
</style>
	<meta charset="utf-8">
	 <link href="http://libs.baidu.com/bootstrap/3.0.3/css/bootstrap.min.css" rel="stylesheet">
	<script src="<%=basePath%>js/qrcode.min.js"></script>
</head>
<body style="margin-top:-20px;">
<div class="row">
		<div class="col-md-12" style="margin-top:20px;">
	 		<div class="panel panel-info">
	 			<div class="panel-heading">产品管理 <a> > </a> 课程类别信息列表</div>
<!-- 头部 -->
<div class="contHtm" style="margin-left: 30px;margin-top:30px;">
<!-- 头部 -->
<!-- 头部 -->
<div class="contHtm" style="margin-left: 30px;">
<span>账号等级:</span>
<select name="empGrade" id="empGrade" style="width: 100px;height: 35px">
		<option value=" ">--全部--</option>
		<option value="0" >运营部</option>
		<option value="1" >门店</option>
	</select>
	<span><input type="text" name="ename" id="ename" placeholder="请输入账号或工号" style="width: 200px;height: 35px;"></span>
	<button style="width: 100px;height: 35px;" onclick="search()">查找</button>
	
</div>
<!-- 列表部 -->
<div class="table-responsive" style="padding: 20px 20px">
	<table class="table">
		<thead>
		<tr>
			<th>序号</th>
			<th>账户</th>
			<th>账户编号</th>		
			<th>姓名</th>
			<th>头像</th>
			<th>工号</th>
			<th>账户等级</th>
			<th>员工角色</th>
			<th>申请时间</th>
			<th>操作</th>
		</tr>
		</thead>
		<%-- <c:forEach items="${result.data}" var="data">
		<tr>
			<td>${data.empId}</td>
			<td>${data.empAccount}</td>
			<td>${data.empNo}</td>
			<td>${data.empProvince}</td>
			<td>${data.empName}</td>
			<td>${data.empImg}</td>
			<td>${data.empNumber}</td>
			<td>${data.empCreate}</td>
			<td>
			<!--  -->
			<button  onclick="edit(${data.empId})" title="修改">修改</button>
			<button  onclick="deletes(${data.empId })" title="删除">删除</button>
		</tr>
		</c:forEach> --%>
		<tbody class="context">
			

		</tbody>
	</table>
	<form>
		<input type="hidden" class="form-control" id="pageCount" name="pageCount"> 
		<input type="hidden" class="form-control" id="pageNo" value="1" name="pageNo">
	</form>
	<div style="padding-right: 20px; widows: 100%; height: 100%" id="pageContext">
		<div class="tcdPageCode"></div>
	</div>
</div>
</div>
</div>
</div>
<script src="<%=basePath%>js/jquery-1.8.3.min.js"></script>
<script src="<%=basePath%>js/jquery.page.js"></script>
<script type="text/javascript">
	//删除
	function ondelete(empId,empStatus){
	
		$.ajax({
			type:'post',
			contentType:"application/json;charset=UTF-8",
			url:'<%=basePath%>'+"bsEmployee/editEmployee",
			data:JSON.stringify({
				"empId":empId,
				"empStatus":empStatus
			}),
			dataType:"json",
			success:function(data){
				 console.log(data);
				if(data.code==400){
					window.location.reload(); 
				}
				
			}
		});
	}
	function edit(empId){
		window.location.href="bsEmployee/queryDetail?uid="+empId;
	}	
	//加载
	$(function(){
		var pageNo = $("#pageNo").val();
		getList(pageNo, 15, null, null);
	});
	
	//分页
	function getRecourcesAction(result) {
	    if (result != null) {
	       $("#pageContext").html("");
		   $("#pageContext").html('<div class="tcdPageCode"></div>');
	       $(".tcdPageCode").createPage({   
		        pageCount: result.totalPage,
		        current: $("#pageNo").val(),
		        backFn: function (p) {
		        	$("#pageNo").val(p);
		        	var pageNo = $("#pageNo").val();
					getList(pageNo, 15, null, null);
		        }
	       });
	    } 
	}
	//获取员工信息列表
	function getList(pageNo,pageSize,empGrade,ename){
		$.ajax({
 	        url:'<%=basePath%>'+"bsEmployee/queryByPage",
 	        data: {
 	        	"pageNo":pageNo,
 	        	"pageSize":pageSize,
 	        	"empGrade":empGrade,
 	        	"ename":ename
 	        },
 	        type: "get",
 	        dataType: "JSON",
 	        success: function(data) {
 	        	 if(data != null && data.code==200){
 	        		var htm = '';
 	        		var list = data.data;
    	            var pageNo = $("#pageNo").val();
    	            if(pageNo !=undefined && pageNo != null && pageNo == 1){
        	             getRecourcesAction(data);
    	            }
    	              
    	            for(var i =0;i<list.length;i++){
    	               var  empGrade = " ";
     	            	 if(list[i].empGrade==0){
     	            		empGrade="运营部门";
     	            	 }else if(list[i].empGrade==1){
     	            		empGrade ="门店";
     	            	 }
     	            	 var  empRole = " ";
     	            	 if(list[i].empRole==0){
     	            		empRole="超级管理员";
     	            	 }else if(list[i].empRole==1){
     	            		empRole ="普通员工";
     	            	 } 
     	            	 
     	            var empCreate = timeStamp2String(list[i].empCreate);
    	            	htm += '<tr class="active">';
    	            	htm += '<td empId="'+list[i].empId+'">'+(i+1)+'</td>';
    	            	htm += '<td>'+list[i].empAccount+'</td>';
    	            	htm += '<td>'+list[i].empNo+'</td>';   	     
    	            	htm += '<td>'+list[i].empName+'</td>';
    	            	htm += '<td><img src="'+list[i].empImg+'" width="60px" height="40px"></td>';
    	            	htm += '<td>'+list[i].empNumber +'</td>';
    	              	htm += '<td>'+empGrade+'</td>';
    	              	htm += '<td>'+empRole+'</td>';
    	            	htm += '<td>'+empCreate+'</td>';
    	            	htm += '<td><button style="margin-right: 10px;"  onclick="edit('+list[i].empId+')" title="修改">修改</button>';
    	            	  if(list[i].empStatus==0){
    	            	htm+='<button style="margin-right: 10px;"  onclick="ondelete('+list[i].empId+',1)" title="启用">启用</button>'	; 
    	            	  }else{
    	            	htm+='<button style="margin-right: 10px;"  onclick="ondelete('+list[i].empId+',0)" title="禁用">禁用</button>'	;  	  
    	            	  }
    	            
    	            	htm +='</tr>';
    	            }
    	            
    	            $(".context").html(htm);
    	            $("#pageCount").val(data.totalPage);
 	        	 }
 	        }
 	    });
	}
	function search(){
		var empGrade = $("#empGrade").val();
		var ename = $("#ename").val();
		getList(1,15,empGrade,ename)
	}
	
	
	
	  
    //时间格式化
   	function timeStamp2String(time){
   	    var datetime = new Date();
   	    datetime.setTime(time);
   	    var year = datetime.getFullYear();
   	    var month = datetime.getMonth() + 1 < 10 ? "0" + (datetime.getMonth() + 1) : datetime.getMonth() + 1;
   	    var date = datetime.getDate() < 10 ? "0" + datetime.getDate() : datetime.getDate();
   	    var hour = datetime.getHours()< 10 ? "0" + datetime.getHours() : datetime.getHours();
   	    var minute = datetime.getMinutes()< 10 ? "0" + datetime.getMinutes() : datetime.getMinutes();
   	    var second = datetime.getSeconds()< 10 ? "0" + datetime.getSeconds() : datetime.getSeconds();
   	    return year + "-" + month + "-" + date+" "+hour+":"+minute+":"+second;
   	}
</script>
</body>
</html>
